package com.hello.sky.controller.admin;


import com.hello.sky.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping({"/admin/shop", "/user/shop"})
public class ShopController {

    private static final String SHOP_STATUS = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/status")
    public Result getStatus(){
        String status = (String) redisTemplate.opsForValue().get(SHOP_STATUS);
        assert status != null;
        return Result.success(Integer.valueOf(status));
    }

    @PutMapping("/{status}")
    public Result updateStatus(@PathVariable("status") Integer status){
        redisTemplate.opsForValue().set(SHOP_STATUS, status.toString());
        return Result.success();
    }
}
